/*
* Copyright (C) 2020 ~ 2024 chaigec All Rights Reserved.
*
* Author:     chaigec <chaigec@163.com>
* Maintainer: chaigec <chaigec@163.com>

 * Use of this source code is governed by MIT license that can be found in the
 * LICENSE file in the root of the source tree. All contributing project authors
 * may be found in the AUTHORS file in the root of the source tree.
*/

#include "MkUtil/MkBase64.h"
#include <gtest/gtest.h>

TEST(MkBase64, DecodeAndEncode)
{
    MkString strTmp = "123";
    MkString strEncode;
    Uint32 ErrorCode =  MkBase64Encode(strTmp, strEncode);
    EXPECT_EQ(NoneError, ErrorCode);
    MkString strDecode;
    ErrorCode = MkBase64Decode(strEncode, strDecode);
    EXPECT_EQ(NoneError, ErrorCode);
    EXPECT_STREQ(strDecode.c_str(), strTmp.c_str());
}

TEST(MkBase64, Encode)
{
    MkString strEncode;
    Uint32 ErrorCode = MkBase64Encode("1234", strEncode);
    EXPECT_EQ(NoneError, ErrorCode);
    ErrorCode = MkBase64Encode("12345", strEncode);
    EXPECT_EQ(NoneError, ErrorCode);
}

TEST(MkBase64, DecodeError)
{
    MkString strDecode;
    Uint32 ErrorCode = MkBase64Decode("12341", strDecode);
    EXPECT_NE(NoneError, ErrorCode);
    MkString strEncode;
    ErrorCode = MkBase64Encode("1234", strEncode);
    EXPECT_EQ(NoneError, ErrorCode);
    strEncode = strEncode.substr(1) + "=";
    ErrorCode = MkBase64Decode(strEncode, strDecode);
    EXPECT_NE(NoneError, ErrorCode);
}

